#include <iostream>
#include <unistd.h>
#include <string>
#include <unordered_map>
#include <vector>
#include <functional>

typedef std::function<void()> func;

//是一个函数指针数组
std::vector<func> callback;
std::unordered_map<int,std::string> desc;

void readMysql()
{
    std::cout << "sub process["<< getpid() << "] 执行获取数据库信息\n" << std::endl;
}

void execuleUrl()
{
    std::cout << "sub process[" << getpid() << "] 执行url解析\n" << std::endl;
}

void cal()
{
    std::cout << "sub process[" << getpid() << "] 执行加密任务\n" << std::endl;
}

void save()
{
    std::cout << "sub process[" << getpid() << "] 执行数据持久化任务\n" << std::endl;
}

//加载
void load()
{
    desc.insert({callback.size(),"readMysql : 执行获取数据库信息"});
    callback.push_back(readMysql);

    desc.insert({callback.size(),"execuleUrl : 执行url解析"});
    callback.push_back(execuleUrl);

    desc.insert({callback.size(),"cal : 执行加密任务"});
    callback.push_back(cal);

    desc.insert({callback.size(),"save : 执行数据持久化任务"});
    callback.push_back(save);
}

//展示干啥的
void showHandler()
{
    std::cout << "----------------------------" << std::endl;
    for(auto e:desc)
    {
        std::cout << e.first << "\t" << e.second << std::endl;
    }
    std::cout << "----------------------------" << std::endl;
}

//显示有多少命令
int showSize()
{
    return callback.size();
}